package cn.itcast.documentapis;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 10:23 2019/3/8
 * @Version 1.0
 **/
public class esClient {

    //获取连接
    public static TransportClient getClient() {
        TransportClient client = null;
        //添加集群名称
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
        try {
            client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.217.128"), 9300));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return client;
    }
}
